package com.nancy.java_design.visitor.demo1;

import java.util.ArrayList;
import java.util.List;

/**
 * 结构对象体
 */
public class VisitorStructure {
    // 存储元素的集合
    private List<Animal> animalList = new ArrayList<Animal>();

    // 添加元素
    public void add(Animal animal) {
        animalList.add(animal);
    }

    // 遍历所有元素
    public void accept(Visitor visitor) {
        for (Animal animal : animalList) {
            animal.accept(visitor);
        }
    }

}
